
package com.lzb.musicplayer.dialog;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lxj.xpopup.core.AttachPopupView;
import com.lzb.musicplayer.R;

public class PlaylistEditDialog extends AttachPopupView implements View.OnClickListener {

    private TextView tvPlay, tvPlayNext, tvRename, tvDelete, tvSave;


    public PlaylistEditDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_playlist_edit;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
    }

    protected void initView() {
        tvPlay = findViewById(R.id.tvPlay);
        tvPlayNext = findViewById(R.id.tvPlayNext);
        tvRename = findViewById(R.id.tvRename);
        tvDelete = findViewById(R.id.tvDelete);
        tvSave = findViewById(R.id.tvSave);

        tvPlay.setOnClickListener(this);
        tvPlayNext.setOnClickListener(this);
        tvRename.setOnClickListener(this);
        tvDelete.setOnClickListener(this);
        tvSave.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tvPlay) {//播放
            dismiss();
            if (listener != null) {
                listener.clickItem(0);
            }
        } else if (id == R.id.tvPlayNext) {//下一首播放
            dismiss();
            if (listener != null) {
                listener.clickItem(1);
            }
        } else if (id == R.id.tvRename) {//重命名
            dismiss();
            if (listener != null) {
                listener.clickItem(2);
            }
        } else if (id == R.id.tvDelete) {//删除
            dismiss();
            if (listener != null) {
                listener.clickItem(3);
            }
        } else if (id == R.id.tvSave) {//保存为文件
            dismiss();
            if (listener != null) {
                listener.clickItem(4);
            }
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickItem(int pos);
    }

}
